
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */

import java.sql.*;

final class ViewAccount extends javax.swing.JInternalFrame {
    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    PreparedStatement statement;
    String searchValue="";
    Thread viewAccountThread=new Thread();
    Thread viewAccountTitleThread=new Thread();
    /** Creates new form ViewCredit */
    public ViewAccount() {
        initComponents();
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Account Code", "Name", "Description", "Bank", "Account Number", "Balance", "Currency", "Type", "Value", "Status", "Trading Type", "Activity"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        /* Execute submit thread */
        viewAccountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable("");
            }
        });
        viewAccountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountThread.isAlive())setProcessingTitle(viewAccountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        viewAccountThread.start();
        viewAccountTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jActivateButton = new javax.swing.JButton();
        jFreezeButton = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ViewAccount.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Account Code", "Name", "Bank Name", "Account Number", "Unit", "Balance", "Currency", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N

        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jActivateButton.setIcon(resourceMap.getIcon("jActivateButton.icon")); // NOI18N
        jActivateButton.setText(resourceMap.getString("jActivateButton.text")); // NOI18N
        jActivateButton.setName("jActivateButton"); // NOI18N
        jActivateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jActivateButtonActionPerformed(evt);
            }
        });

        jFreezeButton.setIcon(resourceMap.getIcon("jFreezeButton.icon")); // NOI18N
        jFreezeButton.setText(resourceMap.getString("jFreezeButton.text")); // NOI18N
        jFreezeButton.setName("jFreezeButton"); // NOI18N
        jFreezeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFreezeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(373, Short.MAX_VALUE)
                .addComponent(jRefreshButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jActivateButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFreezeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCancelButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFreezeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jActivateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed
        /* Execute submit thread */
        viewAccountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable("");
            }
        });
        viewAccountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountThread.isAlive())setProcessingTitle(viewAccountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        viewAccountThread.start();
        viewAccountTitleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed
                                              
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. View Account - Processing Request");
            thread.sleep(500);
            this.setTitle("::. View Account - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. View Account - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. View Account - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
       
        if(viewAccountThread.isAlive())
        {
            try{
                viewAccountThread.stop();
                viewAccountTitleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. View Account");
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

    public void reset()
    {
        viewAccountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable("");
            }
        });
        viewAccountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountThread.isAlive())setProcessingTitle(viewAccountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        viewAccountThread.start();
        viewAccountTitleThread.start();
    }
    public void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private void activateButton()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Account !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            int row=jTable1.getSelectedRow();
            String accountCode=jTable1.getValueAt(row,0).toString();
            activateAccount(accountCode);
        }
        refreshTable(searchValue);
    }
    private void jActivateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jActivateButtonActionPerformed
        
        viewAccountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                activateButton();
            }
        });
        viewAccountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountThread.isAlive())setProcessingTitle(viewAccountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        viewAccountThread.start();
        viewAccountTitleThread.start();
    }//GEN-LAST:event_jActivateButtonActionPerformed

    void activateAccount(String accountCode)
    {
        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+"  prnActivateAccount"+Connect.procInitStart+"?"+Connect.procInitEnd);
         try{
                    statement.setString(1,accountCode);

                    System.out.println("Activate Account "+accountCode);
            }
            catch(Exception e)
            {
            System.out.println("ViewAccount.activateAccount gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        //Connect.closeConnection();
    }
    private void jFreezeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFreezeButtonActionPerformed
        
        viewAccountThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                freezeButton();
            }
        });
        viewAccountTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountThread.isAlive())setProcessingTitle(viewAccountTitleThread);
                enableControls();
                System.out.println("accountThread stopped runing.");
            }
        });
        viewAccountThread.start();
        viewAccountTitleThread.start();
    }//GEN-LAST:event_jFreezeButtonActionPerformed
    private void freezeButton()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Account !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            int row=jTable1.getSelectedRow();
            String accountCode=jTable1.getValueAt(row,0).toString();
            freezeAccount(accountCode);
        }
        refreshTable(searchValue);
    }
    public void freezeAccount(String accountCode)
    {
        Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+"  prnFreezeAccount"+Connect.procInitStart+"?"+Connect.procInitEnd);
         try{
                    statement.setString(1,accountCode);
                    System.out.println("Freeze "+accountCode);

            }
            catch(Exception e)
            {
            System.out.println("ViewAccount.freezeAccount gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
    private void disableControls()
    {
        jRefreshButton.setEnabled(false);
        jFreezeButton.setEnabled(false);
        jActivateButton.setEnabled(false);
    }
    private void enableControls()
    {
        jRefreshButton.setEnabled(true);
        jFreezeButton.setEnabled(true);
        jActivateButton.setEnabled(true);
        this.setTitle("::. View Account");
    }
    public void refreshTable(String searchPara)
    {
        //old method for capturing table records
//        String[] accountCode=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",1);
//        String[] accountName=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",2);
//        String[] accountBankCode=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",3);
//        String[] accountNumber=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",4);
//        String[] accountUnit=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",5);
//        String[] accountBalance=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",6);
//        String[] accountStatus=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",7);
//        String[] accountDescription=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",8);
//        String[] accountValue=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",9);
//        String[] accountCategory=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",10);
//        String[] accountTradingType=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",13);
//        String[] accountActivity=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",14);
        
        //New mechanism for capturing table record. Shows over 50% more efficient in speed
        String[][] accountTable=systems.getTableDataArrayNum(OpenMSApp.Database_A,"Account",1,2,3,4,5,6,7,8,9,10,13,14);

        String[] accountCode=accountTable[0];
        String[] accountName=accountTable[1];
        String[] accountBankCode=accountTable[2];
        String[] accountNumber=accountTable[3];
        String[] accountUnit=accountTable[4];
        String[] accountBalance=accountTable[5];
        String[] accountStatus=accountTable[6];
        String[] accountDescription=accountTable[7];
        String[] accountValue=accountTable[8];
        String[] accountCategory=accountTable[9];
        String[] accountTradingType=accountTable[10];
        String[] accountActivity=accountTable[11];
            if(searchPara.isEmpty()==false)
            {
                searchValue=searchPara;
                String multipleSearch[]=searchPara.split(",");
                String queryPara="where (cAccountCode = '"+multipleSearch[0]+"') or (vAccountName = '"+multipleSearch[0]+"') or (vAccountNumber like '"+multipleSearch[0]+"') ";

                for(int k=1;k<multipleSearch.length;k++)
                {
                    queryPara+="or (cAccountCode like '%"+multipleSearch[k]+"%') or (vAccountName like '%"+multipleSearch[k]+"%') or (vAccountNumber like '%"+multipleSearch[k]+"%') ";
                }

//                accountCode=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 1);
//                accountName=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 2);
//                accountBankCode=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 3);
//                accountNumber=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 4);
//                accountUnit=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 5);
//                accountBalance=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 6);
//                accountStatus=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 7);
//                accountDescription=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 8);
//                accountValue=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 9);
//                accountCategory=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 10);
//                accountTradingType=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 13);
//                accountActivity=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 14);
                
                accountTable=systems.getColumn(OpenMSApp.Database_A, "Select * from Account "+queryPara, 1,2,3,4,5,6,7,8,9,10,13,14);
                accountCode=accountTable[0];
                accountName=accountTable[1];
                accountBankCode=accountTable[2];
                accountNumber=accountTable[3];
                accountUnit=accountTable[4];
                accountBalance=accountTable[5];
                accountStatus=accountTable[6];
                accountDescription=accountTable[7];
                accountValue=accountTable[8];
                accountCategory=accountTable[9];
                accountTradingType=accountTable[10];
                accountActivity=accountTable[11];
            }

        int x=0;
        int y=accountCode.length;

        tableObject=new Object[y][12];

        while(x<y)
        {
            String accountBankName=systems.getValue(OpenMSApp.Database_A, "Select * from Bank Where cBankCode='"+accountBankCode[x]+"'", "vName").trim();

            tableObject[x][0]=accountCode[x].trim();
            tableObject[x][1]=accountName[x].trim();
            tableObject[x][2]=accountDescription[x].trim();
            tableObject[x][3]=accountBankName;
            tableObject[x][4]=accountNumber[x].trim();
            try
            {
                tableObject[x][5]=systems.converToRealMoneyFormat(accountBalance[x]);
            }
            catch(Exception e)
            {
                tableObject[x][5]="Er!M1C01K0";
            }
            tableObject[x][6]=accountUnit[x].trim();
            tableObject[x][7]=accountCategory[x].trim();
            tableObject[x][8]=accountValue[x].trim();
            tableObject[x][9]=accountStatus[x].trim();
            if(accountTradingType[x]==null)
            {
                accountTradingType[x]="N/A";                
            }
            if(accountActivity[x]==null)
            {
                accountActivity[x]="N/A";                
            }
            tableObject[x][10]=accountTradingType[x].trim();
            tableObject[x][11]=accountActivity[x].trim();
            systems.freeHeap();
            x+=1;
            if(x==y){break;}
       }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Account Code", "Name", "Description", "Bank", "Account Number", "Balance", "Currency", "Type", "Value", "Status", "Trading Type", "Activity"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });


    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jActivateButton;
    private javax.swing.JButton jCancelButton;
    private javax.swing.JButton jFreezeButton;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
